package NextClass.Native;

import com.sun.net.httpserver.HttpExchange;
import vm.runtime.NextVMRuntime;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class NextHashmap implements Serializable {
    public static String[] ClassMethods = {
            "get",
            "put",
            "cls",
            "has",
            "to_str",
            "rm"
    };
    public static Object run(String Invoke, Object object,NextVMRuntime nextVMRuntime, Object... objects) throws Exception{
        HashMap<Object,Object> hashMap = (HashMap<Object, Object>) object;
        if (Invoke.equals("put")) {
            hashMap.put(objects[0] , objects[1]);
            return null;
        }
        else if (Invoke.equals("get")) {
            return hashMap.get(objects[0]);
        }
        else if (Invoke.equals("cls")) {
            hashMap.clear();
            return null;
        }
        else if (Invoke.equals("has")) {
            return hashMap.containsKey(objects[0]);
        }
        else if (Invoke.equals("to_str")) {
            return hashMap.toString();
        }
        else if (Invoke.equals("rm")) {
            return hashMap.remove(objects[0]);
        }
        else if (Invoke.equals("keys")) {
            return new ArrayList<>(Arrays.asList(hashMap.keySet().toArray(new Object[0])));
        }
        else {
            return null;
        }
    }
}
